package com.test.impl.test1;



import com.test.impl.entity.req.AxSignReqFourElementsOfEnterpriseBusinessDto;
import com.test.impl.entity.res.AxSignResFourElementsOfEnterpriseBusinessDto;
import com.test.impl.entity.res.BankDto;
import com.test.interfaces.parentface.JarRuleParentFace;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能概述:jar包规则a
 *
 * @author maoxiaomeng
 * @date 20221008
 */
@Api(tags = "jar包规则a")
public class JarRuleImplA implements JarRuleParentFace {


    @ApiOperation(value = "查询企业信息", notes = "查询企业详情,测试数据,businessId请传递1,传递2时会演示业务异常")
    public AxSignResFourElementsOfEnterpriseBusinessDto querySth(@ApiParam(value = "社会信用代码", required = true) String businessId, @ApiParam(value = "企业名称", required = false) String businessName) {
        if ("2".equals(businessId) || "2".equals(businessName)) {
            throw new IllegalArgumentException("非法的企业 id(名称)");
        }
        return data.get(businessId);
    }

    @ApiOperation(value = "查询企业信息2", notes = "查询企业详情,测试数据,businessId请传递1,传递2时会演示业务异常")
    public AxSignResFourElementsOfEnterpriseBusinessDto querySth2(@ApiParam(value = "企业工商四要素", required = true) AxSignReqFourElementsOfEnterpriseBusinessDto requestDto) {
        if ("2".equals(requestDto.getOrgIdentificationNumber()) || "2".equals(requestDto.getOrganizationName())) {
            throw new IllegalArgumentException("非法的企业 id(名称)");
        }
        return data.get(requestDto.getOrgIdentificationNumber());
    }

    @ApiOperation(value = "两数相加", notes = "返回两数之和")
    public Integer sum(@ApiParam("数字1") Integer num1, @ApiParam("数字2") Integer num2) {
        return num1 + num2;
    }

    @ApiOperation(value = "字符串替换", notes = "返回替换后的字符串")
    public String replace(@ApiParam(value = "字符串", required = true) String str, @ApiParam(value = "目标字符", required = true) String target, @ApiParam("替换字符") String replace) {
        if (str.isEmpty()) {
            throw new IllegalArgumentException("字符串不允许为空");
        }
        return str.replace(target, replace);
    }


    //模拟库查询
    public static Map<String, AxSignResFourElementsOfEnterpriseBusinessDto> data = new HashMap<>();

    static {
        AxSignResFourElementsOfEnterpriseBusinessDto res = new AxSignResFourElementsOfEnterpriseBusinessDto();
        BankDto bankDto = new BankDto();
        bankDto.setBankName("天地银行")
                .setPassword("123")
                .setResponseMessage("ddd")
                .setUsername("maoxiaomeng")
                .setVerification("1024");
        res.setBankDto(bankDto);
        res.setResponseCode("0000")
                .setResponseMessage("成功")
                .setTraceNo("1234876543")
                .setTxSN("TX" + "1234876543")
                .setVerification("101010");

        data.put("1", res);

        AxSignResFourElementsOfEnterpriseBusinessDto res2 = new AxSignResFourElementsOfEnterpriseBusinessDto();
        BankDto bankDto2 = new BankDto();
        bankDto.setBankName("一家大银行")
                .setPassword("abc")
                .setResponseMessage("success")
                .setUsername("maoxiaomeng")
                .setVerification("521");
        res2.setBankDto(bankDto2);
        res2.setResponseCode("10000")
                .setResponseMessage("success")
                .setTraceNo("1234876543")
                .setTxSN("TX" + "1234876543")
                .setVerification("0001111");
        res2.getBankDto().setBankName("一家大银行");
        data.put("2", res2);
    }
}
